home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Window.h
-
- Contains: Definition of TWindow, a base class which provides a
- framework for building way-cool windows which even John
- Sullivan would be happy with. Floating windows and “smart
- zooming” algorithms are based on code samples provided by
- Dean Yu.
-
- Written by: Dave Falkenburg, Dean Yu
-
- Copyright: © 1993-1995 by Dave Falkenburg, all rights reserved.
-
- Change History (most recent first):
-
- <8> 1/24/95 DRF Make DoMenuSelection return a Boolean, just like DoMenuCommand.
- <7> 1/20/95 DRF Add a field to track whether a TWindow needs to be disposed via
- DisposeDialog. Thanks to Gary W. Powell @ Adobe for reporting
- the bug.
- <6> 1/3/95 DRF Add Nitin’s changes for Drag handling: a ClickAndDrag method.
- <5> 1/3/95 DRF Protected TWindow::Window because it is not legal to create a
- TWindow without subclassing. Also revised DoMenuSelection to use
- a typedef-ed parameter.
- <4> 11/12/94 DRF Added AdjustMenusBeforeMenuSelection.
- <3> 11/8/94 DRF Add some better menu handling methods.
- <2> 9/4/94 DRF Added DrawJustTheGrowIcon.
-
- */
-
- #ifndef _WINDOW_
- #define _WINDOW_
- #pragma once
-
- #include <Types.h>
- #include <Windows.h>
- #include <Events.h>
- #include <Drag.h>
-
- #include "EventDispatcher.h"
- #include "AECoreSuite.h"
- #include "WindowManager.h"
-
-
- typedef short WindowTemplateID;
-
-
- //--------------------------------------------------------------------------------
- class TWindow :
- public TWindowEventDispatcher,
- public virtual MAEWindow
- {
- public:
- static WindowRef GetNewWindow(short windowID, WindowRef behind, WindowLayer layer = kNormalWindowLayer);
- static WindowRef NewWindow(const Rect &boundsRect, ConstStr255Param title, Boolean visible, short theProc, WindowRef behind, Boolean goAwayFlag, long refCon, WindowLayer layer = kNormalWindowLayer);
-
- static void SuspendApplication(void);
- static void ResumeApplication(void);
- static void BeginModalDialog(void);
- static void EndModalDialog(void);
-
- protected:
- WindowRef fWindow;
-
- public:
- TWindow(WindowRef aWindowRef);
- void IWindow();
- virtual void Dispose();
- virtual ~TWindow() = 0;
-
- // Event routing methods
-
- virtual Boolean EventFilter(EventRecord * theEvent);
-
- // Methods you shouldn’t need to override, but might need to
-
- virtual void Select(void);
- virtual void ShowHide(Boolean showFlag);
-
- // Methods which probably should be overridden
-
- virtual void AdjustCursor(Point where);
- virtual void Activate(void);
- virtual void Deactivate(void);
-
- virtual void Draw(void);
- virtual void DrawGrowIcon(void);
- virtual void Click(EventRecord * anEvent);
- virtual void KeyDown(EventRecord * anEvent);
-
- virtual Rect GetGrowSizeRect(void);
- virtual void AdjustForNewWindowSize(Rect * oldRect,Rect * newRect);
-
- // Window property accessor methods…
-
- virtual Rect GetBounds() const;
- virtual Boolean HasCloseBox() const;
- virtual Boolean HasTitleBar() const;
- virtual long GetIndex() const;
- virtual Boolean IsFloating() const;
- virtual Boolean IsModal() const;
- virtual Boolean IsResizable() const;
- virtual Boolean IsZoomable() const;
- virtual Boolean IsZoomed() const;
- virtual Boolean IsVisible() const;
-
- virtual Rect SetBounds(Rect r);
- virtual long SetIndex(long index);
- virtual Boolean SetZoomed(Boolean zoomed);
- virtual Boolean SetVisible(Boolean show);
-
- virtual Boolean CanClose(void);
- virtual Boolean Close(DescType saveOptions = kAEAsk);
- virtual Boolean DeleteAfterClose(void);
-
- // Methods for handling menus & menu commands
-
- virtual void AdjustMenus(void);
- // virtual Boolean DispatchMenuCommand(MenuCommand command);
- // virtual Boolean DispatchMenuSelection(MenuSelection& selection);
-
- // Methods for use with the Drag Manager
-
- virtual void ClickAndDrag(EventRecord * anEvent);
- // NOTE: This method takes GLOBAL coordinates
- // because that’s what TrackDrag expects.
-
- virtual OSErr HandleDrag(DragTrackingMessage dragMessage,DragReference theDrag);
-
- virtual OSErr DragEnterWindow(DragReference theDrag);
- virtual OSErr DragInWindow(DragReference theDrag);
- virtual OSErr DragLeaveWindow(DragReference theDrag);
-
- virtual OSErr HandleDrop(DragReference theDragRef);
-
- virtual Boolean IsPointInContentRgn( Point pt );
- virtual Boolean IsMouseInContentRgn( DragReference dragRef );
- virtual Rect GetContentsBounds(void);
-
- // TWindowEventDispatcher overrides
-
- virtual Boolean DispatchContentClick(EventRecord& event, WindowRef window);
- virtual Boolean DispatchUpdate(EventRecord& event);
- virtual Boolean DispatchActivateOrResume(EventRecord& event);
- virtual Boolean DispatchDeactivateOrSuspend(EventRecord& event);
-
- virtual Boolean TrackDrag(EventRecord& event, WindowRef window);
- virtual Point TrackGrow(EventRecord& event, WindowRef window);
- virtual Boolean TrackGoAway(EventRecord& event, WindowRef window);
- virtual Boolean TrackZoomIn(EventRecord& event, WindowRef window);
- virtual Boolean TrackZoomOut(EventRecord& event, WindowRef window);
-
- // AEOM Support
- virtual void AEGetNameDesc(CAEDesc& value, const CAETypeList& requestedTypes = fgWildcardTypeList) const;
- virtual void AESetNameDesc(const CAEDesc& name);
- virtual void HandleAEClose(AEServerEvent& event);
-
- // Class methods
- static TWindow* GetWindowObject(WindowRef aWindow);
- static TWindow* GetNthWindow(long index, WindowLayer = kNormalWindowLayer);
- static TWindow* GetNamedWindow(ConstStr255Param name, WindowLayer = kNormalWindowLayer);
-
- private:
- static DragTrackingHandler fgDragTrackingHandler;
- static DragReceiveHandler fgDragReceiveHandler;
-
- // Toolbox callbacks
- static pascal OSErr CallWindowDragTrackingHandler(DragTrackingMessage message,WindowRef theWindow,void *handlerRefCon,DragReference theDragRef);
- static pascal OSErr CallWindowDragReceiveHandler(WindowRef theWindow, void *handlerRefCon,DragReference theDragRef);
- };
-
- class WithModalDialogHilite
- {
- private:
- static int fgNestLevel;
-
- public:
- WithModalDialogHilite();
- ~WithModalDialogHilite();
- };
-
- inline Rect GetWindowBounds(WindowRef w) { return GetWindowPort(w)->portRect; }
-
-
- #endif
-